package com.ruoyi.collection.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.collection.domain.DeferredReq;
import com.ruoyi.collection.domain.ProductDeferredVO;
import com.ruoyi.collection.service.IDeferredService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @author ljz
 * @description
 * @date 2022/6/27
 */
@Slf4j
@RestController
public class DeferredController {

    @Autowired
    private IDeferredService deferredService;

    @RequestMapping("/forcollection/findTodayBuyDeferredInfoByLoanNos")
    @Log(title = "查询借据今天是否有购买延期金融包及按钮置灰状态", businessType = BusinessType.GET)
    public JSONObject findTodayBuyDeferredInfoByLoanNos(@RequestBody String res){
        if (JSON.parseObject(res) != null && JSON.parseObject(res).getJSONObject("data") != null) {
            DeferredReq deferredReq = JSONObject.parseObject(JSON.parseObject(res).getString("data"),  DeferredReq.class);
            log.info("ljz:调用业务系统findTodayBuyDeferredInfoByLoanNos进行查询--- paramsJson:" + res);
            return deferredService.findTodayBuyDeferredInfoByLoanNos(deferredReq.getLoanNos());
        }
        return null;
    }


    @RequestMapping("/forcollection/getDeferredByLoanNo")
    @Log(title = "根据借据号列表获取可用延期金融包", businessType = BusinessType.GET)
    public List<ProductDeferredVO> getDeferredByLoanNos(@RequestBody String res){
        if (JSON.parseObject(res) != null && JSON.parseObject(res).getJSONObject("data") != null) {
            DeferredReq deferredReq = JSONObject.parseObject(JSON.parseObject(res).getString("data"),  DeferredReq.class);
            log.info("ljz:调用业务系统getDeferredByLoanNo进行查询--- paramsJson:" + res);
            return deferredService.getDeferredByLoanNo(deferredReq.getLoanNo());
        }
        return Collections.emptyList();
    }
}
